package cn.com.dhcc.adam.spring.mvc.four;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class UserContoller {

	@InitBinder
	protected void initBinder(WebDataBinder binder) {
		binder.setValidator(new UserValidator());
	}
	
	@RequestMapping("/user")
	public String userInfo(@RequestParam(required=false) String userName, Model model){
		model.addAttribute("info", userName);
		return "user";
	}

	@RequestMapping(value="/uinfo", method=RequestMethod.GET)
	public void processFoo(@Valid @RequestParam User user, Model model){
		model.addAttribute("info", "hello valid");
		
	}
	
}
